package com.cj.mobile.iabp.app.utils;

import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

import androidx.annotation.NonNull;

import com.cj.mobile.iabp.mvp.model.entity.MainEvent;

import org.simple.eventbus.EventBus;

/**
 * Android实现部分文字可点击及变色
 * TextView userAgreement = findViewById(R.id.user_agreement);
 * SpannableString agreement = new SpannableString("Agree to the User Agreement and Privacy Policy");
 * agreement.setSpan(new MyClickableSpan("User Agreement"), 13, 27, SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
 * agreement.setSpan(new MyClickableSpan("Privacy Policy"), 32, 46, SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
 * userAgreement.setText(agreement);
 * userAgreement.setMovementMethod(LinkMovementMethod.getInstance());
 */
public class EsignClickableSpan extends ClickableSpan {

    public EsignClickableSpan() {
    }

    @Override
    public void onClick(@NonNull View view) {
        EventBus.getDefault().post(new MainEvent(EventBusTags.REFRESH_BOX_TAG), EventBusTags.CLICKABLE_SPAN_TAG);
    }

    @Override
    public void updateDrawState(@NonNull TextPaint ds) {
        super.updateDrawState(ds);
        ds.setColor(Color.parseColor("#46C788"));
        ds.setUnderlineText(false);
    }
}